define(function(require, exports, module) {
	// 因为涉及兼容性问题，可以通过req.header('x-forwarded-for')与req.connection.remoteAddress来获取IP地址
	function getClientIp(req) {
	    var ipAddress;
	    var forwardedIpsStr = req.header('x-forwarded-for'); 
	    if (forwardedIpsStr) {
	        var forwardedIps = forwardedIpsStr.split(',');
	        ipAddress = forwardedIps[0];
	    }
	    if (!ipAddress) {
	        ipAddress = req.connection.remoteAddress;
	    }
	    return ipAddress;
	}
	// 获取本机IP地址
	function getLocalIP_onWin(){
		var os=require('os');
		var ifaces=os.networkInterfaces();
		for (var dev in ifaces) {
		  var alias=0;
		  ifaces[dev].forEach(function(details){
		    if (details.family=='IPv4') {
		      console.log(dev+(alias?':'+alias:''),details.address);
		      ++alias;
		    }
		  });
		}
	}
	// 在mac上获取本地IP地址
	function getLocalIPonMac(){
		var os = require('os');
		var IPv4,hostName;
		hostName=os.hostname();
		for(var i=0;i<os.networkInterfaces().en0.length;i++){
		    if(os.networkInterfaces().en0[i].family=='IPv4'){
		        IPv4=os.networkInterfaces().en0[i].address;
		    }
		}
		console.log('----------local IP: '+IPv4);
		console.log('----------local host: '+hostName);
	}
	// 在ubuntu server上获取本地IP地址
	function getLocalIP_onUbuntu(){
		var os = require('os');
		var IPv4,hostName;
		hostName=os.hostname();
		for(var i=0;i<os.networkInterfaces().eth0.length;i++){
		    if(os.networkInterfaces().eth0[i].family=='IPv4'){
		        IPv4=os.networkInterfaces().eth0[i].address;
		    }
		}
		console.log('----------local IP: '+IPv4);
		console.log('----------local host: '+hostName);
	}

	// 获取外网IP地址
	// 查看本机外网IP,可以访问一下几个网站：
	// http://www.net.cn/static/customercare/yourIP.asp
	// http://www.ip138.com/
	// http://www.viewip.info/
	// http://www.123cha.com/
	// http://tool.chinaz.com/Ip/
	// http://ip.qq.com
	function getIp(){
		//需要添加库：npm install jquery 
		//          npm install iconv-lite
		var $ = require('jquery'),
		    iconv = require('iconv-lite'),
		    http = require('http');


		var options = {
		    host:'ip.qq.com',
		    port:80,
		    path:'/'
		};

		var html = "";//http获取html字符串
		http.get(options, function (res) {
		    res.setEncoding('binary');//or hex
		    res.on('data',function (data) {//加载数据,一般会执行多次
		        html += data;
		    }).on('end', function () {
		            html=iconv.decode(new Buffer(html,'binary'), 'GBK');//把gbk编码转换成
		            var dom = $(html);
		            var ip=dom.find("#login_show .red").text();
		            if(ip.split('.').length==4){
		                console.log('server ip: '+ip);
		            }
		        })
		});		
	}
});